import Copy from '$tp/copy'
const className = 'fxm'
const Index = ({ table_name, database }) =>{
	// let t = keys?.[0]
	// if(keys.length > 1) {
	// 	keys = keys.reverse()
	// 	t = keys[keys.length - 1]
	// }
	return  {
		modal:{
			// title:`【${ rows()[0].table_name }】表结构`,
			title: <span>【<b className='c3'>{ table_name }</b>】表结构</span>,
			width: '100%',
			maxWidth:null,
			controls: 0
		},
		table: {
			api:'mysql/show_columns',
			param: { table_name, database },
			idStr: 'COLUMN_NAME',
			paging:0,
			cols:[
				{ title: '字段名', 			dataIndex: 'COLUMN_NAME', 				width:100, render: t => {
					return (
						<div className={className} onClick={e=>e.stopPropagation()}>
							<b className='ar f13 ex'>{t}</b>
							<Copy t={t}/>
						</div>
					)
				}},
				{ title: '类型', 			dataIndex: 'COLUMN_TYPE', 				width:100, render: t => {
					return (
						<div className={className} onClick={e=>e.stopPropagation()}>
							<b className='ar f13 ex c3'>{t}</b>
							<Copy t={t}/>
						</div>
					)
				}},
				{ title: '是否空', 			dataIndex: 'IS_NULLABLE', 				width:50, align:'center', render: t => {
					return t === 'NO' ? <b className='c1'>{t}</b> : <b className='g9'>{t}</b>
				} },
				{ title: '主键类型', 		dataIndex: 'COLUMN_KEY', 				width:100, align:'center', render: t => <b className='c4 ar ex'>{t}</b> },
				{ title: '默认值', 			dataIndex: 'COLUMN_DEFAULT', 			width:100, render: t => {
					return (
						<div className={className} onClick={e=>e.stopPropagation()}>
							<div className='ex fxm'>
								{
									window.$fn.isString(t) ? <b className='g9 ar'>{t ? t.toLowerCase() : t}</b> : <b>{t}</b>
								}
							</div>
							{
								window.$fn.isString(t) ? <Copy t={t.toLowerCase()}/> : null
							}
						</div>
					)
				} },
				{ title: '额外参数', 		dataIndex: 'EXTRA', 			width:200, ellipsis:1, render: t => {
					let is_def = t?.includes('DEFAULT_GENERATED')
					t = is_def ? t.replace('DEFAULT_GENERATED', '') : t
					return (
						<div className={className} onClick={e=>e.stopPropagation()}>
							<b className='ar ex c0'>{ t !== '' && t ? t.toLowerCase() : t }</b>
							{
								t && <Copy t={ t.toLowerCase() }/>
							}
						</div>
					)
				} },
				{ title: '注释', 			dataIndex: 'COLUMN_COMMENT', 			width:100 },
			]
		}
	}
}
export default Index